<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/template/default/commonLayout.xhtml">

	<ui:define name="content">

		<h:form id="breadCrumb">
			<p:breadCrumb>
				<p:menuitem value="#{msg['index']}" url="./index.xhtml" />
				<p:menuitem value="#{msg['books']}" url="#" />
			</p:breadCrumb>
		</h:form>

		<h1>
			<h:outputText value="#{msg['book.list']}" />
		</h1>

		<h:form>
			<input type="hidden" name="#{_csrf.parameterName}"
				value="#{_csrf.token}" />

			<h:outputLink value="./book-details.xhtml"
				rendered="#{p:ifGranted('ROLE_ADD_BOOK')}">
				<h:outputText value="#{msg['new']}" />
			</h:outputLink>

			<h:messages globalOnly="true" />

			<h:panelGrid id="grid" columns="3" cellpadding="4">

				<p:dataTable var="item" value="#{bookDocBean.findAll()}"
					paginator="true" rows="10"
					paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					rowsPerPageTemplate="5,10,15">
					<p:column headerText="#{msg['id']}">
						<h:outputText value="#{item.id}" />
					</p:column>

					<p:column headerText="#{msg['title']}">
						<h:outputText value="#{item.title}" />
					</p:column>

					<p:column headerText="#{msg['author']}">
						<h:outputText value="#{item.author}" />
					</p:column>

					<p:column headerText="#{msg['pages']}">
						<h:outputText value="#{item.pages}" />
					</p:column>

					<p:column headerText="#{msg['edit']}"
						rendered="#{p:ifGranted('ROLE_EDIT_BOOK')}">
						<h:outputLink value="book-details.xhtml?id=#{item.id}">
							<h:outputText value="E" />
						</h:outputLink>
					</p:column>

					<p:column headerText="#{msg['delete']}"
						rendered="#{p:ifGranted('ROLE_DELETE_BOOK')}">
						<h:commandLink actionListener="#{bookDocBean.delete(item.id)}"
							value="X" />
					</p:column>

				</p:dataTable>

			</h:panelGrid>

		</h:form>

	</ui:define>

</ui:composition>

</html>